package org.openurp.edu.student.info

import org.beangle.commons.inject.bind.AbstractBindModule
import org.openurp.edu.student.info.web.action.ChangepwdAction
import org.openurp.edu.student.info.web.action.HomeAction
import org.openurp.edu.student.info.web.action.LoginAction
import org.openurp.edu.student.info.web.action.ManagerAction
import org.openurp.edu.student.info.web.action.PaymentAction
import org.openurp.edu.student.info.web.action.StudentAction
import org.openurp.edu.student.info.web.action.WelcomeAction
import org.openurp.edu.student.info.web.security.SecurityInterceptor
import org.openurp.edu.student.info.web.action.EnChangepwdAction
import org.openurp.edu.student.info.web.action.AdminAction
import org.openurp.edu.student.info.web.action.ExchangeAction
import org.openurp.edu.student.info.web.action.EnWelcomeAction
import org.openurp.edu.student.info.web.action.MyInforAction
import org.openurp.edu.student.info.web.action.PayrecordAction
import org.openurp.edu.student.info.web.action.ManagerRuanAction
import org.openurp.edu.student.info.web.action.ManagerGuoAction
import org.openurp.edu.student.info.web.action.ManagerTangAction
import org.openurp.edu.student.info.web.action.ManagerHuangAction
import org.openurp.edu.student.info.web.action.ManagerCaoAction
import org.openurp.edu.student.info.web.action.PaymentfinAction
import org.openurp.edu.student.info.web.action.ManagerKuangAction
import org.openurp.edu.student.info.web.action.TeacherAction
import org.openurp.edu.student.info.web.action.PaymentTeacherAction
import org.beangle.notification.mail.JavaMailSender
import org.beangle.commons.inject.PropertySource
import org.openurp.platform.api.app.UrpApp
import org.openurp.edu.student.info.web.action.VisaAction

class DefaultModule extends AbstractBindModule with PropertySource {

  protected def binding(): Unit = {
    bind(classOf[ManagerAction])
    bind(classOf[ManagerTangAction])
    bind(classOf[ManagerGuoAction])
    bind(classOf[ManagerHuangAction])
    bind(classOf[ManagerCaoAction])
    bind(classOf[ManagerRuanAction])
    bind(classOf[ManagerKuangAction])
    bind(classOf[StudentAction])
    bind(classOf[LoginAction])
    bind(classOf[WelcomeAction])
    bind(classOf[EnWelcomeAction])
    bind(classOf[HomeAction])
    bind(classOf[EnChangepwdAction])
    bind(classOf[ExchangeAction])
    bind(classOf[ChangepwdAction])
    bind(classOf[PaymentAction])
    bind(classOf[PaymentfinAction])
    bind(classOf[PayrecordAction])
    bind(classOf[AdminAction])
    bind(classOf[MyInforAction])
    bind(classOf[TeacherAction])
    bind(classOf[PaymentTeacherAction])
    bind(classOf[VisaAction])
    bind(classOf[JavaMailSender])
      .property("host", $("mail.host"))
      .property("port", $("mail.port"))
      .property("username", $("mail.username"))
      .property("password", $("mail.password"))
      .property("from", $("mail.from"))
      .property("javaMailProperties", props("mail.smtp.auth=true"))

    bind("web.Interceptor.mysecurity", classOf[SecurityInterceptor])
  }

  def properties: collection.Map[String, String] = {
    val props = new collection.mutable.HashMap[String, String]
    props.put("mail.port", "25")
    UrpApp.getUrpAppFile foreach { f =>
      scala.xml.XML.loadFile(f) \\ "mail" foreach { elem =>
        List("host", "username", "password", "port", "from") foreach { x =>
          (elem \\ x) foreach { cs =>
            props.put("mail." + x, cs.child.head.text)
          }
        }
      }
    }
    props
  }
}
